package com.sailfish.springbootdemo.common;

import com.sailfish.springbootdemo.configs.UserHeaderHolder;
import com.sailfish.springbootdemo.dao.db1.PcbaCompanyDao;
import com.sailfish.springbootdemo.pojo.db1.PcbaCompany;
import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.mongodb.core.aggregation.ArrayOperators;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class StrToCompanys {

    @Autowired
    private PcbaCompanyDao pcbaCompanyDao;

    /**
     * 根据字符串 得到对应的CompanyList
     */
    public List<PcbaCompany> getPcbaCompanyListFromStr() {
        List<PcbaCompany> list = new ArrayList<>();
        String pcbas = UserHeaderHolder.getPcbas();
        if ("".equals(pcbas)) {
            list = pcbaCompanyDao.getAllCompany(null, null);
        } else {
            for (String s : pcbas.split(",")) {
                PcbaCompany pcbaCompany = pcbaCompanyDao.getPcbaCompanyById(Integer.parseInt(s));
                if (pcbaCompany != null) {
                    list.add(pcbaCompany);
                }
            }
        }
        return list;
    }

    /**
     * 根据字符串 得到对应的CompanyIdList
     */
    public List<Integer> getPcbaCompanyIdListFromStr() {
        List<Integer> idList = new ArrayList<>();
        String pcbas = UserHeaderHolder.getPcbas();
        if ("".equals(pcbas)) {

        } else {
            for (String s : pcbas.split(",")) {
                idList.add(Integer.parseInt(s));
            }
        }
        return idList;
    }
}
